package user_ser

import (
	"giv-vue-blog/service/redis_ser"
	"giv-vue-blog/utils/jwts"
	"time"
)

func (UserService) UserLogout(claims *jwts.CustomClaims, token string) error {
	//需要计算距离现在的过期时间。从上述的claims可以拿到expiresAt时间
	exp := claims.ExpiresAt              //过期时间
	now := time.Now()                    //现在时间
	diff := exp.Time.Sub(now)            //相差时间
	return redis_ser.Logout(token, diff) //优化过后的 之前的代码是下方的
	////将相差的时间以key的方式写到redis中
	//err := global.Redis.Set(fmt.Sprintf("logout_%s", token), "", diff).Err()
	//return err
}
